package org.example.service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 浩瀚小贷数据清理服务接口
 * 用于按月份平均删除浩瀚小贷未结清数据，保持剩余金额不超过六亿
 */
public interface HaohanLoanDataCleanupService {
    
    /**
     * 获取浩瀚小贷未结清订单的总剩余金额
     * @return 总剩余金额
     */
    BigDecimal getTotalRemainAmount();
    
    /**
     * 获取浩瀚小贷未结清订单按月份分组统计
     * @return 按月份分组的订单统计信息
     */
    List<MonthlyOrderStats> getMonthlyOrderStats();
    
    /**
     * 执行数据清理，按月份平均删除数据
     * @param targetRemainAmount 目标剩余金额（不超过六亿）
     * @return 清理结果统计
     */
    CleanupResult executeCleanup(BigDecimal targetRemainAmount);
    
    /**
     * 按月份删除指定数量的订单及相关数据
     * @param month 月份（格式：yyyy-MM）
     * @param deleteCount 删除数量
     * @return 删除结果
     */
    DeleteResult deleteOrdersByMonth(String month, int deleteCount);
    
    /**
     * 月度订单统计信息
     */
    class MonthlyOrderStats {
        private String month;
        private int totalCount;
        private BigDecimal totalRemainAmount;
        private List<String> orderNos;
        
        // 构造函数、getter和setter
        public MonthlyOrderStats(String month, int totalCount, BigDecimal totalRemainAmount, List<String> orderNos) {
            this.month = month;
            this.totalCount = totalCount;
            this.totalRemainAmount = totalRemainAmount;
            this.orderNos = orderNos;
        }
        
        public String getMonth() { return month; }
        public void setMonth(String month) { this.month = month; }
        public int getTotalCount() { return totalCount; }
        public void setTotalCount(int totalCount) { this.totalCount = totalCount; }
        public BigDecimal getTotalRemainAmount() { return totalRemainAmount; }
        public void setTotalRemainAmount(BigDecimal totalRemainAmount) { this.totalRemainAmount = totalRemainAmount; }
        public List<String> getOrderNos() { return orderNos; }
        public void setOrderNos(List<String> orderNos) { this.orderNos = orderNos; }
    }
    
    /**
     * 清理结果统计
     */
    class CleanupResult {
        private boolean success;
        private String message;
        private BigDecimal originalAmount;
        private BigDecimal finalAmount;
        private int totalDeletedOrders;
        private int totalDeletedCustomers;
        private int totalDeletedRepayPlans;
        
        // 构造函数、getter和setter
        public CleanupResult(boolean success, String message) {
            this.success = success;
            this.message = message;
        }
        
        public boolean isSuccess() { return success; }
        public void setSuccess(boolean success) { this.success = success; }
        public String getMessage() { return message; }
        public void setMessage(String message) { this.message = message; }
        public BigDecimal getOriginalAmount() { return originalAmount; }
        public void setOriginalAmount(BigDecimal originalAmount) { this.originalAmount = originalAmount; }
        public BigDecimal getFinalAmount() { return finalAmount; }
        public void setFinalAmount(BigDecimal finalAmount) { this.finalAmount = finalAmount; }
        public int getTotalDeletedOrders() { return totalDeletedOrders; }
        public void setTotalDeletedOrders(int totalDeletedOrders) { this.totalDeletedOrders = totalDeletedOrders; }
        public int getTotalDeletedCustomers() { return totalDeletedCustomers; }
        public void setTotalDeletedCustomers(int totalDeletedCustomers) { this.totalDeletedCustomers = totalDeletedCustomers; }
        public int getTotalDeletedRepayPlans() { return totalDeletedRepayPlans; }
        public void setTotalDeletedRepayPlans(int totalDeletedRepayPlans) { this.totalDeletedRepayPlans = totalDeletedRepayPlans; }
    }
    
    /**
     * 删除结果
     */
    class DeleteResult {
        private boolean success;
        private String message;
        private int deletedOrders;
        private int deletedCustomers;
        private int deletedRepayPlans;
        private BigDecimal deletedAmount;
        
        // 构造函数、getter和setter
        public DeleteResult(boolean success, String message) {
            this.success = success;
            this.message = message;
        }
        
        public boolean isSuccess() { return success; }
        public void setSuccess(boolean success) { this.success = success; }
        public String getMessage() { return message; }
        public void setMessage(String message) { this.message = message; }
        public int getDeletedOrders() { return deletedOrders; }
        public void setDeletedOrders(int deletedOrders) { this.deletedOrders = deletedOrders; }
        public int getDeletedCustomers() { return deletedCustomers; }
        public void setDeletedCustomers(int deletedCustomers) { this.deletedCustomers = deletedCustomers; }
        public int getDeletedRepayPlans() { return deletedRepayPlans; }
        public void setDeletedRepayPlans(int deletedRepayPlans) { this.deletedRepayPlans = deletedRepayPlans; }
        public BigDecimal getDeletedAmount() { return deletedAmount; }
        public void setDeletedAmount(BigDecimal deletedAmount) { this.deletedAmount = deletedAmount; }
    }
}
